package com.yuerlive.rainbow.module.live.presenter;

import com.yuerlive.rainbow.api.LiveApi;
import com.yuerlive.rainbow.api.LiveService;
import com.yuerlive.rainbow.base.BasePresenterImpl;
import com.yuerlive.rainbow.entity.BaseData;
import com.yuerlive.rainbow.entity.ContributionData;
import com.yuerlive.rainbow.rx.RxHelper;
import com.yuerlive.rainbow.rx.RxObserver;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by xiaoyi on 2017/6/14.
 */

public class ContributionPresenter extends BasePresenterImpl implements ContributionContract.Presenter {
    LiveService liveService;
    ContributionContract.View view;

    int page = 1;

    public ContributionPresenter(ContributionContract.View view) {
        this.view = view;
        this.view.setPresenter(this);
        liveService = LiveApi.getInstance().liveService;
    }

    @Override
    public void getContributionList(String userId, boolean loadMore) {
        view.showLoading();
        Map<String, String> params = new HashMap<>();
        params.put("upUserId", userId);
        liveService.getContributionList(params).compose(RxHelper.toUI())
                .subscribe(new RxObserver<BaseData<List<ContributionData>>>(this) {
                    @Override
                    protected void onSuccess(BaseData<List<ContributionData>> listBaseData) {
                        view.hideLoading();
                        view.showContributionList(listBaseData.getObject(), loadMore);
                    }

                    @Override
                    protected void onFail(String message) {

                    }
                });
    }

    @Override
    public void refresh(String userId) {
        page = 1;
        getContributionList(userId, true);
    }
}
